package top.codedance.iotp.server.net.handle;

import top.codedance.iotp.common.constent.Command;
import top.codedance.iotp.common.entity.CommonEntity;
import top.codedance.iotp.server.ServerApplication;
import top.codedance.iotp.server.net.TcpServer;
import top.codedance.iotp.server.net.handle.configuration.ClientHandlerConfig;
import cd.io.netty.channel.ChannelHandlerContext;
import cd.io.netty.channel.SimpleChannelInboundHandler;
import org.apache.log4j.Logger;

public class ClientCommonHandler extends SimpleChannelInboundHandler<CommonEntity> {
    private static Logger logger = ServerApplication.getLogger(ClientCommonHandler.class);

    protected void messageReceived(ChannelHandlerContext channelHandlerContext, CommonEntity commonEntity) throws Exception {
        if(ClientHandlerConfig.syncCmds.contains(commonEntity.getCommand()) || Command.NONE == commonEntity.getCommand()) {
            logger.debug("COMMAND_RECEIVE: Command: " + commonEntity.getCommand());
            TcpServer.syncRequestService.ackSyncMsg(commonEntity);
        }else{
            channelHandlerContext.fireChannelRead(commonEntity); //向后传递
        }
    }
}
